<template>
	<view class="bg-gray" style="height: auto;">
		<cu-custom bgColor="bg-informatic-brown" isBack>
			<block slot="backText">返回</block>
			<block slot="content">个人简历</block>
			<block slot="right" v-if="editable">
				<view class="padding-right-xl" @click="toEdit()">编辑</view>
			</block>
		</cu-custom>
		<view class="solids padding-top-sm padding-bottom-sm">
			<component :is="template" component="profile_show" :data="student" :padding="true"></component>
			<component :is="template" component="edu_show" :data="edus"></component>
			<component :is="template" component="project_show" :data="project"></component>
			<component :is="template" component="award_show" :data="award"></component>
			<component :is="template" component="memo_show" :data="memo"></component>
		</view>
	</view>
</template>

<script>
	import default_panel from './components/default/panel.vue';
	import template_1 from './components/template1/panel.vue'
	let app = require("@/config");
	var rwx = require('labs/rwx.js');
	export default {
		components: { default_panel, template_1 },
		data() {
			return {
				project: [],
				award: [],
				student: {},
				edus: {},
				userCode: "",
				memo: "",
				editable: false,
				template: 'template_1'
			}
		},
		methods: {
			toEdit() {
				uni.navigateTo({
					url: './resume'
				});
			},
			back() {
				console.log('back');
				uni.navigateTo({
					url: '../index/index'
				});
			}
		},
		onLoad(e) {
			let _uuid = e.uuid;
			uni.showLoading();
			uni.post("/api/resume/GetResume",{uuid: _uuid},msg => {
				uni.hideLoading();
				if (msg.success) {
					this.student = {
						name: msg.basic.RealName,
						age: msg.basic.Age,
						nation: msg.basic.Ethnicity,
						politics: msg.basic.Politic,
						tel: msg.basic.Mobile,
						mail: msg.basic.Email,
						gender: msg.basic.Gender
					};
					var data = [];
					for (let i = 0; i < msg.exps.length; i++) {
						data.push({
							start: msg.exps[i].BeginTime,
							end: msg.exps[i].EndTime,
							name: msg.exps[i].Name,
							organization: msg.exps[i].DepartName,
							detail: msg.exps[i].Description,
							job: msg.exps[i].Position
						});
					}
					this.project = [];
					this.project = data;
					data = [];
					for (let i = 0; i < msg.awards.length; i++) {
						data.push({
							start: msg.awards[i].BeginTime,
							end: msg.awards[i].EndTime,
							name: msg.awards[i].Name,
							organization: msg.awards[i].DepartName,
							detail: msg.awards[i].Description,
							job: msg.awards[i].Position
						});
					}
					this.award = [];
					this.award = data;
					data = [];
					for (let i = 0; i < msg.edus.length; i++) {
						data.push({
							start: msg.edus[i].BeginTime,
							end: msg.edus[i].EndTime,
							school: msg.edus[i].Name,
							majure: msg.edus[i].DepartName,
							lecture: msg.edus[i].Description,
						});
					}
					this.edus = [];
					this.edus = data;
					this.memo = msg.basic.Memo;
					if (app.userInfo.userCode == msg.userCode && app.userInfo.userCode != "") {
						this.editable = true;
					}
					
					rwx.ready((wx) => {
						let shareObj = {
							title: `${msg.basic.RealName}的简历`, // 分享标题
							desc: `${msg.basic.RealName}的简历`, // 分享描述
							link: `http://unify.xmu.edu.cn/mob/iuc/resume/show?uuid=${msg.basic.ID}`, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
							imgUrl: app.webInfo.avatar, // 分享图标
							success: function () {
							}
						};
						console.log(shareObj);
						wx.updateAppMessageShareData(shareObj);
						wx.updateTimelineShareData(shareObj);
					})
				} else {
					uni.showToast({
						title: msg.msg,
						icon: 'none'
					});
				}
			});
			uni.showLoading();
			uni.post("/api/resume/GetResumeTemplate", {}, msg => {
				uni.hideLoading();
				if (msg.success) {
					// this.resumeData = msg;
					this.template = msg.data
				} else {
					uni.showToast({
						title: msg.msg,
						icon: 'none'
					});
				}
			});
		}
	}
</script>

<style>
	.panel {
		/* width: 100%; */
		margin: 10px;
		padding: 10px;
		height: auto;
	}
	
	.panel-header {
		display: flex;
		flex-direction: row;
		align-items: baseline;
		justify-content: space-between;
	}
	
	.word-warp {
		word-wrap: break-word;
		word-break: break-all;
		overflow: hidden;
	}
</style>